const Mock = require('mockjs');

Mock.mock(process.env.VUE_APP_BASE_API_CONTEXT + '/test/get1', 'get', function(options) {
  console.log('/get1');
  console.log(options);
  /*
  只有三个属性
  {
    body: null
    type: "GET"
    url: "/api/test/test/get1"
  }
  */
  // return res.json({
  //   code: 20000,
  //   message: 'success',
  //   source: 'test',
  //   data: Mock.mock({
  //     _id: "@id()",
  //     title: "@id()",
  //     complete: false
  //   })
  // });

  return {
    code: 20000,
    message: 'success',
    source: 'test',
    data: Mock.mock({
      _id: "@id()",
      title: "@id()",
      complete: false
    })
  };
});

Mock.mock(process.env.VUE_APP_BASE_API_CONTEXT + '/test/get2', 'get', function(options) {
  console.log('/get2');
  console.log(options);
  return {
    code: 20000,
    message: 'success',
    source: 'test',
    data: Mock.mock({
      _id: "@id()",
      title: "@id()",
      complete: false
    })
  };
});

Mock.mock(process.env.VUE_APP_BASE_API_CONTEXT + '/test/get3', 'get', function(options) {
  console.log('/get3');
  console.log(options);
  return {
    code: 20000,
    message: 'success',
    source: 'test',
    data: Mock.mock({
      _id: "@id()",
      title: "@id()",
      complete: false
    })
  };
});

Mock.mock(process.env.VUE_APP_BASE_API_CONTEXT + '/test/post1', 'post', function(options) {
  console.log('/post1');
  console.log(options);
  return {
    code: 20000,
    message: 'success',
    source: 'test',
    data: Mock.mock({
      _id: "@id()",
      title: "@id()",
      complete: false
    })
  };
});

Mock.mock(process.env.VUE_APP_BASE_API_CONTEXT + '/test/post2', 'post', function(options) {
  console.log('/post2');
  console.log(options);
  // var o = options.body ? JSON.parse(options.body) : {};
  return {
    code: 20000,
    message: 'success',
    source: 'test',
    data: Mock.mock({
      _id: "@id()",
      title: 'default-title',//o.title || 'default-title',
      complete: false
    })
  };
});

Mock.mock(process.env.VUE_APP_BASE_API_CONTEXT + '/test/post3', 'post', function(options) {
  console.log('/post3');
  console.log(options);
  // var o = options.body ? JSON.parse(options.body) : {};
  return {
    code: 20000,
    message: 'success',
    source: 'test',
    data: Mock.mock({
      _id: "@id()",
      title: 'default-title',//o.title || 'default-title',
      complete: false
    })
  };
});
